{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "[[5. 5. 5.]\n",
      " [1. 5. 5.]]\n",
      "2\n",
      "<class 'numpy.ndarray'>\n",
      "[[5. 5. 5.]\n",
      " [1. 1. 1.]]\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pylab\n",
    "\n",
    "def myprint(i):\n",
    "    print(type(i))\n",
    "    print(i)\n",
    "    print(np.linalg.matrix_rank(i))\n",
    "\n",
    "\n",
    "i0=np.full((2,3),5.0)\n",
    "i0[1,0]=1\n",
    "myprint(i0)\n",
    "i0[1:2] = 1\n",
    "myprint(i0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "[[1. 0. 0.]\n",
      " [0. 1. 0.]\n",
      " [0. 0. 1.]]\n",
      "3\n",
      "<class 'numpy.matrix'>\n",
      "[[1. 0. 0.]\n",
      " [0. 1. 0.]\n",
      " [0. 0. 1.]]\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "i1=np.eye(3)\n",
    "myprint(i1);\n",
    "\n",
    "i2=np.matrix(i1)\n",
    "myprint(i2);\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  2  3  4  5  6  7  8  9 10 11]\n",
      "[  0   1   4   9  16  25  36  49  64  81 100 121]\n",
      "[1 1 3 8 5]\n",
      "[ 1  1  9 64 25]\n",
      "[ 0  1  2  3  4  5  6  7  8  9 10 11]\n"
     ]
    }
   ],
   "source": [
    " a = np.arange(12)\n",
    "aa = a**2\n",
    "print(a)\n",
    "print(aa)\n",
    "i = np.array( [ 1,1,3,8,5 ] )\n",
    "print(i)\n",
    "print(aa[i])\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 用布尔值来索引："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[False False False False False  True  True  True  True  True  True  True]\n",
      "[0 1 2 3 4 0 0 0 0 0 0 0]\n"
     ]
    }
   ],
   "source": [
    "print(a>4)\n",
    "a[a>4]=0\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ix_()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(array([[[2]],\n",
      "\n",
      "       [[3]],\n",
      "\n",
      "       [[4]],\n",
      "\n",
      "       [[5]]]), array([[[8],\n",
      "        [5],\n",
      "        [4]]]), array([[[5, 4, 6, 8, 3]]]))\n"
     ]
    }
   ],
   "source": [
    "a = np.array([2,3,4,5])\n",
    "b = np.array([8,5,4])\n",
    "c = np.array([5,4,6,8,3])\n",
    "d = np.ix_(a,b,c)\n",
    "print(d)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
